package com.haelth.control;

import java.io.IOException;

import javax.swing.JTextArea;

import org.jsoup.Connection;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import com.haelth.comman.basic.BaseQuery;

public class HealthOneQuery extends BaseQuery {
	/**
	 * 
	 */
	private String txt;
	private static final long serialVersionUID = 1L;

	public String getTxt() {
		return txt;
	}

	public void setTxt(String txt) {
		this.txt = txt;
	}


	public void findbyId() throws IOException {

		cont = Jsoup
				.connect("http://www.nhi.gov.tw/Query/query1_list.aspx?Q1ID="
						+ txt);
		Document doc = cont.get();
		Elements trs = doc.select("tr");

		// 找到最後一筆
		int i = -1;
		for (Element element : doc.select("tr")) {
			i = i + 1;
			System.out.println(i);
		}
		System.out.println(trs.get(i).text());
		// 印出最後一筆資料
		int j = -1;
		for (Element element : trs.get(i).select("td")) {
			j = j + 1;
			switch (j) {
			case 1:
				Resault.append("代碼：" + element.text() + "\n");
				break;
			case 2:
				Resault.append("名稱(英文)：" + element.text() + "\n");
				break;
			case 3:
				Resault.append("名稱(中文)：" + element.text() + "\n");
				break;
			case 8:
				Resault.append("健保價：" + element.text() + "\n");
				break;
			case 10:
				Resault.append("藥廠：" + element.text() + "\n");
				break;
			case 9:
				Resault.append("起訖：" + element.text() + "\n");
				break;
			}
			;
		}
		dispose();
	}

	@SuppressWarnings("deprecation")
	public void run() {
		try {
			findbyId();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
